#include <bits/stdc++.h>
using namespace std;
#define int long long
void solve()
{
    int n,m;
    cin>>n>>m;
    vector<int> v(n+1),w(n+1);
    unordered_map<int, int>mp;
    for(int i=1;i<=n;i++)
    {
        cin>>v[i];
        mp[v[i]]++;
    }
    int mn=0x3f3f3f3f,mx=0;
    for(int i=1;i<=n;i++)
    {
        cin>>w[i];
        mn=min(w[i]+v[i],mn);
        mx=max(mx,v[i]+w[i]);
    }
    //int ans=0;
    for(int i=1;i<=mx;i++)
    {
        if(m>=mp[i])
        {
            mp[i+1]+=mp[i];
            m-=mp[i];
            //cout<<m<<endl;
            mp[i]=0;
        }
        else 
        {
            cout<<min(mn,i)<<endl;
            return ;
        }
    }
    cout<<mn<<endl;
}
signed main()
{
    //ios::sync_with_stdio(false);
    //cin.tie(nullptr);
    int T=1;
    //cin>>T;
    while(T--)
    {
       solve();
    }
    return 0;
}